﻿/**
 * jQuery EasyUI 1.2.6
 * 
 * Licensed under the GPL terms To use it on other terms please contact us
 * 
 * Copyright(c) 2009-2012 stworthy [ stworthy@gmail.com ]
 * 
 */
(function() {
	var plugins = {
		draggable : {
			js : "jquery.draggable.js"
		},
		droppable : {
			js : "jquery.droppable.js"
		},
		resizable : {
			js : "jquery.resizable.js"
		},
		linkbutton : {
			js : "jquery.linkbutton.js",
			css : "linkbutton.css"
		},
		progressbar : {
			js : "jquery.progressbar.js",
			css : "progressbar.css"
		},
		pagination : {
			js : "jquery.pagination.js",
			css : "pagination.css",
			dependencies : [ "linkbutton" ]
		},
		datagrid : {
			js : "jquery.datagrid.js",
			css : "datagrid.css",
			dependencies : [ "panel", "resizable", "linkbutton", "pagination" ]
		},
		treegrid : {
			js : "jquery.treegrid.js",
			css : "tree.css",
			dependencies : [ "datagrid" ]
		},
		propertygrid : {
			js : "jquery.propertygrid.js",
			css : "propertygrid.css",
			dependencies : [ "datagrid" ]
		},
		panel : {
			js : "jquery.panel.js",
			css : "panel.css"
		},
		window : {
			js : "jquery.window.js",
			css : "window.css",
			dependencies : [ "resizable", "draggable", "panel" ]
		},
		dialog : {
			js : "jquery.dialog.js",
			css : "dialog.css",
			dependencies : [ "linkbutton", "window" ]
		},
		messager : {
			js : "jquery.messager.js",
			css : "messager.css",
			dependencies : [ "linkbutton", "window", "progressbar" ]
		},
		layout : {
			js : "jquery.layout.js",
			css : "layout.css",
			dependencies : [ "resizable", "panel" ]
		},
		form : {
			js : "jquery.form.js"
		},
		menu : {
			js : "jquery.menu.js",
			css : "menu.css"
		},
		tabs : {
			js : "jquery.tabs.js",
			css : "tabs.css",
			dependencies : [ "panel", "linkbutton" ]
		},
		splitbutton : {
			js : "jquery.splitbutton.js",
			css : "splitbutton.css",
			dependencies : [ "linkbutton", "menu" ]
		},
		menubutton : {
			js : "jquery.menubutton.js",
			css : "menubutton.css",
			dependencies : [ "linkbutton", "menu" ]
		},
		accordion : {
			js : "jquery.accordion.js",
			css : "accordion.css",
			dependencies : [ "panel" ]
		},
		calendar : {
			js : "jquery.calendar.js",
			css : "calendar.css"
		},
		combo : {
			js : "jquery.combo.js",
			css : "combo.css",
			dependencies : [ "panel", "validatebox" ]
		},
		combobox : {
			js : "jquery.combobox.js",
			css : "combobox.css",
			dependencies : [ "combo" ]
		},
		combotree : {
			js : "jquery.combotree.js",
			dependencies : [ "combo", "tree" ]
		},
		combogrid : {
			js : "jquery.combogrid.js",
			dependencies : [ "combo", "datagrid" ]
		},
		validatebox : {
			js : "jquery.validatebox.js",
			css : "validatebox.css"
		},
		numberbox : {
			js : "jquery.numberbox.js",
			dependencies : [ "validatebox" ]
		},
		searchbox : {
			js : "jquery.searchbox.js",
			css : "searchbox.css",
			dependencies : [ "menubutton" ]
		},
		spinner : {
			js : "jquery.spinner.js",
			css : "spinner.css",
			dependencies : [ "validatebox" ]
		},
		numberspinner : {
			js : "jquery.numberspinner.js",
			dependencies : [ "spinner", "numberbox" ]
		},
		timespinner : {
			js : "jquery.timespinner.js",
			dependencies : [ "spinner" ]
		},
		tree : {
			js : "jquery.tree.js",
			css : "tree.css",
			dependencies : [ "draggable", "droppable" ]
		},
		datebox : {
			js : "jquery.datebox.js",
			css : "datebox.css",
			dependencies : [ "calendar", "combo" ]
		},
		datetimebox : {
			js : "jquery.datetimebox.js",
			dependencies : [ "datebox", "timespinner" ]
		},
		slider : {
			js : "jquery.slider.js",
			dependencies : [ "draggable" ]
		},
		parser : {
			js : "jquery.parser.js"
		}
	};
	var locals = {
		"af" : "easyui-lang-af.js",
		"bg" : "easyui-lang-bg.js",
		"ca" : "easyui-lang-ca.js",
		"cs" : "easyui-lang-cs.js",
		"cz" : "easyui-lang-cz.js",
		"da" : "easyui-lang-da.js",
		"de" : "easyui-lang-de.js",
		"en" : "easyui-lang-en.js",
		"fr" : "easyui-lang-fr.js",
		"nl" : "easyui-lang-nl.js",
		"zh_CN" : "easyui-lang-zh_CN.js",
		"zh_TW" : "easyui-lang-zh_TW.js"
	};
	var _3 = {};
	function appendScript(src, callBack) {
		var flag = false;
		var script = document.createElement("script");
		script.type = "text/javascript";
		script.language = "javascript";
		script.src = src;
		script.onload = script.onreadystatechange = function() {
			if (!flag
					&& (!script.readyState || script.readyState == "loaded" || script.readyState == "complete")) {
				flag = true;
				script.onload = script.onreadystatechange = null;
				if (callBack) {
					callBack.call(script);
				}
			}
		};
		document.getElementsByTagName("head")[0].appendChild(script);
	}
	;
	function _9(url, callBack) {
		appendScript(url, function() {
			document.getElementsByTagName("head")[0].removeChild(this);
			if (callBack) {
				callBack();
			}
		});
	}
	;
	function appendCss(href, callBack) {
		var _f = document.createElement("link");
		_f.rel = "stylesheet";
		_f.type = "text/css";
		_f.media = "screen";
		_f.href = href;
		document.getElementsByTagName("head")[0].appendChild(_f);
		if (callBack) {
			callBack.call(_f);
		}
	}
	;
	function importDependencies(_11, _12) {
		_3[_11] = "loading";
		var _13 = plugins[_11];
		var _14 = "loading";
		var _15 = (easyloader.css && _13["css"]) ? "loading" : "loaded";
		if (easyloader.css && _13["css"]) {
			if (/^http/i.test(_13["css"])) {
				var url = _13["css"];
			} else {
				var url = easyloader.base + "themes/" + easyloader.theme + "/"
						+ _13["css"];
			}
			appendCss(url, function() {
				_15 = "loaded";
				if (_14 == "loaded" && _15 == "loaded") {
					_16();
				}
			});
		}
		if (/^http/i.test(_13["js"])) {
			var url = _13["js"];
		} else {
			var url = easyloader.base + "plugins/" + _13["js"];
		}
		appendScript(url, function() {
			_14 = "loaded";
			if (_14 == "loaded" && _15 == "loaded") {
				_16();
			}
		});
		function _16() {
			_3[_11] = "loaded";
			easyloader.onProgress(_11);
			if (_12) {
				_12();
			}
		}
		;
	}
	;
	/*
	 * 处理依赖
	 */
	function dearDependencies(plugin, callBack) {
		var mm = [];
		var _1a = false;
		if (typeof plugin == "string") {
			add(plugin);
		} else {
			for ( var i = 0; i < plugin.length; i++) {
				add(plugin[i]);
			}
		}
		function add(pluginName) {
			if (!plugins[pluginName]) {
				return;
			}
			var d = plugins[pluginName]["dependencies"];
			if (d) {
				for ( var i = 0; i < d.length; i++) {
					add(d[i]);
				}
			}
			mm.push(pluginName);
		}
		;
		function doCallBack() {
			if (callBack) {
				callBack();
			}
			easyloader.onLoad(plugin);
		}
		;
		var _1d = 0;
		function reDearDep() {
			if (mm.length) {
				var m = mm[0];
				if (!_3[m]) {
					_1a = true;
					importDependencies(m, function() {
						mm.shift();// 移除第一个元素，并返回该元素
						reDearDep();
					});
				} else {
					if (_3[m] == "loaded") {
						mm.shift();
						reDearDep();
					} else {
						if (_1d < easyloader.timeout) {
							_1d += 10;
							setTimeout(arguments.callee, 10);
						}
					}
				}
			} else {
				if (easyloader.locale && _1a == true
						&& locals[easyloader.locale]) {
					var url = easyloader.base + "locale/"
							+ locals[easyloader.locale];
					_9(url, function() {
						doCallBack();
					});
				} else {
					doCallBack();
				}
			}
		}
		;
		reDearDep();
	}
	;
	easyloader = {
		modules : plugins,
		locales : locals,
		base : ".",
		theme : "default",
		css : true,
		locale : null,
		timeout : 2000,
		load : function(plugin, callBack) {
			if (/\.css$/i.test(plugin)) {
				if (/^http/i.test(plugin)) {
					appendCss(plugin, callBack);
				} else {
					appendCss(easyloader.base + plugin, callBack);
				}
			} else {
				if (/\.js$/i.test(plugin)) {
					if (/^http/i.test(plugin)) {
						appendScript(plugin, callBack);
					} else {
						appendScript(easyloader.base + plugin, callBack);
					}
				} else {
					dearDependencies(plugin, callBack);
				}
			}
		},
		onProgress : function(_21) {
		},
		onLoad : function(_22) {
		}
	};
	var script = document.getElementsByTagName("script");// 获取所有js引用
	for ( var i = 0; i < script.length; i++) {
		var src = script[i].src;
		if (!src) {
			continue;
		}
		var m = src.match(/easyloader\.js(\W|$)/i);
		if (m) {
			easyloader.base = src.substring(0, m.index);// 获取匹配位置，开始位置
		}
	}
	window.using = easyloader.load;
	if (window.jQuery) {
		jQuery(function() {
			easyloader.load("parser", function() {
				jQuery.parser.parse();// 解析整个文档
			});
		});
	}
})();
